{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 代表的な連続型確率分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:47.490143Z",
     "start_time": "2018-08-25T12:19:47.161901Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy import stats, integrate\n",
    "from scipy.optimize import minimize_scalar\n",
    "from ipywidgets import interact\n",
    "\n",
    "%precision 3\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 図8.5 さまざまな正規分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:47.609264Z",
     "start_time": "2018-08-25T12:19:47.491369Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "28cd0d5f2b074df888f7400328dd686b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='mean', max=3.0, min=-3.0), FloatSlider(value=1.0, de…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(mean=(-3, 3, 0.1), sigma=(0.1, 10.0, 0.1))\n",
    "def N(mean=0, sigma=1):\n",
    "    xs = np.linspace(-6, 6, 1000)\n",
    "    fig = plt.figure(figsize=(10, 6))\n",
    "    ax = fig.add_subplot(111)\n",
    "    rv = stats.norm(mean, sigma)\n",
    "    ax.plot(xs, rv.pdf(xs))\n",
    "    ax.set_xlim(-6, 6)\n",
    "    ax.set_ylim(-0.02, 3)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 図8.7 さまざまな指数分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:47.754158Z",
     "start_time": "2018-08-25T12:19:47.610669Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8f007c47aa454213879e0943c0019a60",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.1, description='l', max=5.0, min=0.1), Output()), _dom_classes=('wid…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(l=(0.1, 5, 0.1))\n",
    "def Ex(l=0.1):\n",
    "    xs = np.linspace(0, 2, 100)\n",
    "    fig = plt.figure(figsize=(10, 6))\n",
    "    ax = fig.add_subplot(111)\n",
    "    rv = stats.expon(scale=1/l)\n",
    "    ax.plot(xs, rv.pdf(xs))\n",
    "    ax.set_xlim(-0.02, 2)\n",
    "    ax.set_ylim(-0.02, 5)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 図8.9 さまざまなカイ二乗分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:47.902488Z",
     "start_time": "2018-08-25T12:19:47.755763Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a98a52a190f946c7ae95e4f44ab459b7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=1, description='n', max=20, min=1), Output()), _dom_classes=('widget-int…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(n=(1, 20, 1))\n",
    "def chi2(n=1):\n",
    "    xs = np.linspace(0, 20, 1000)\n",
    "    fig = plt.figure(figsize=(10, 6))\n",
    "    ax = fig.add_subplot(111)\n",
    "    rv = stats.chi2(n)\n",
    "    ax.plot(xs, rv.pdf(xs))\n",
    "    ax.set_xlim(-0.02, 20)\n",
    "    ax.set_ylim(-0.02, 1)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 図8.11 さまざまなt分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:48.084112Z",
     "start_time": "2018-08-25T12:19:47.904153Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "80c3aec10d7a488bae451782aac92bc2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=1, description='n', max=30, min=1), Output()), _dom_classes=('widget-int…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(n=(1, 30, 1))\n",
    "def t(n=1):\n",
    "    xs = np.linspace(-3, 3, 100)\n",
    "    fig = plt.figure(figsize=(10, 6))\n",
    "    ax = fig.add_subplot(111)\n",
    "    rv = stats.t(n)\n",
    "    ax.plot(xs, rv.pdf(xs), label='t')\n",
    "    rv = stats.norm(loc=0, scale=1)\n",
    "    ax.plot(xs, rv.pdf(xs), 'k', label='N(0, 1)')\n",
    "    ax.set_ylim(-0.02, 0.5)\n",
    "    ax.legend()\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 図8.13 さまざまなF分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-25T12:19:48.206526Z",
     "start_time": "2018-08-25T12:19:48.085227Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c2530dd2abc04c7ea46c28fdad8f7465",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=5, description='n1', max=10, min=1), IntSlider(value=5, description='n2'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(n1=(1, 10, 1), n2=(1, 10, 1))\n",
    "def f(n1=5, n2=5):\n",
    "    xs = np.linspace(0, 6, 200)[1:]\n",
    "    fig = plt.figure(figsize=(10, 6))\n",
    "    ax = fig.add_subplot(111)\n",
    "    rv = stats.f(n1, n2)\n",
    "    ax.plot(xs, rv.pdf(xs))\n",
    "    ax.set_xlim(-0.02, 6)\n",
    "    ax.set_ylim(-0.02, 1)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
